//
//  TCClothesDetailViewController.m
//  Project_B
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "TCClothesDetailViewController.h"
#import "AFNetworkHandler.h"
#import "MBProgressHUD.h"
#import "UIImageView+WebCache.h"
#import "TCMapTableViewCell.h"
#define WIDTH [[UIScreen mainScreen] bounds].size.width / 375
#define HEIGHT [[UIScreen mainScreen] bounds].size.height / 667
@interface TCClothesDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)MBProgressHUD *HUD;
@property (nonatomic, strong)NSMutableArray *dataArr;
@property (nonatomic, strong)NSDictionary *dic;
@end

@implementation TCClothesDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArr = [NSMutableArray array];
    [self getmap];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui@2x"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    [self getData];
}
- (void)getmap
{
    NSString *str = @"brand_id=37&latitude=38.88273434&longitude=121.53933112";
    NSData *data = [str dataUsingEncoding:4];
    [AFNetworkHandler requestPOSTWithURL:@"http://api.lis99.com/v3/zhuangbei/brandshop/0/" body:data comletion:^(id result) {
//        NSLog(@"%@",result);
    }];
}
- (void)getData
{
    NSString *str = [NSString stringWithFormat:@"http://api.lis99.com/v3/zhuangbei/detail/%@/",self.temp.detailid];
    [AFNetworkHandler requestPOSTWithURL:str body:nil comletion:^(id result) {
        self.dic = (NSDictionary *)result;
        [self.dataArr addObjectsFromArray:result[@"data"][@"info"][@"zhuangbeiimg"]];
        [self creatTabView];
        [self.tableView reloadData];
        [self.HUD hide:YES];
    }];
    
}
- (void)creatTabView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375*WIDTH, (667-64)*HEIGHT) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [UIColor colorWithRed:245.0 / 255 green:240.0/255 blue:231.0/255 alpha:1];
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.mode = MBProgressHUDModeIndeterminate;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[TCMapTableViewCell class] forCellReuseIdentifier:@"cell"];
//    self.tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375*WIDTH, 400*HEIGHT)];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375*WIDTH, 300*HEIGHT)];
//    view.backgroundColor = [UIColor cyanColor];
    UIImageView *titleimage = [[UIImageView alloc]initWithFrame:CGRectMake(0*WIDTH, 0*HEIGHT, 375*WIDTH, 240*HEIGHT)];
    titleimage.layer.borderWidth = 0;
    titleimage.layer.borderColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1].CGColor;
    [view addSubview:titleimage];
    [titleimage sd_setImageWithURL:[NSURL URLWithString:self.dic[@"data"][@"info"][@"thumb"]] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
    UILabel *titlelabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 260*HEIGHT, 365*WIDTH, 40*HEIGHT)];
//    titlelabel.backgroundColor = [UIColor whiteColor];
    titlelabel.numberOfLines = 0;
    titlelabel.textColor = [UIColor colorWithRed:153/255.0 green:204/255.0 blue:102/255.0 alpha:1];
    titlelabel.text = self.dic[@"data"][@"info"][@"title"];
    [titlelabel setFont:[UIFont systemFontOfSize:18]];
    [titlelabel sizeToFit];
    [view addSubview:titlelabel];
    UILabel *descriptionlabel = [[UILabel alloc]initWithFrame:CGRectMake(10, titlelabel.frame.origin.y+titlelabel.frame.size.height+10, 355*WIDTH, 40)];
    descriptionlabel.numberOfLines = 0;
    descriptionlabel.textColor = [UIColor orangeColor];
    descriptionlabel.text = self.dic[@"data"][@"info"][@"description"];
    [descriptionlabel sizeToFit];
    [view addSubview:descriptionlabel];
    view.frame = CGRectMake(0, 0, 375*WIDTH, view.frame.size.height+titlelabel.frame.size.height+descriptionlabel.frame.size.height+10*HEIGHT);
    self.tableView.tableHeaderView = view;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 310*HEIGHT;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TCMapTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:self.dataArr[indexPath.row][@"images"]] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
